package dev.ece.util.tools;
/**
 * 方向计算,提供8个方向
 * @author 潜行的虚影
 *
 */
public class Direction {
	
	public final static int DIRECTION_0 = 1;
	
	public final static int DIRECTION_1 = 2;
	
	public final static int DIRECTION_2 = 4;
	
	public final static int DIRECTION_3 = 8;
	
	public final static int DIRECTION_4 = 16;
	
	public final static int DIRECTION_5 = 32;
	
	public final static int DIRECTION_6 = 64;
	
	public final static int DIRECTION_7 = 128;
	
	public final static int DIRECTION_ALL = DIRECTION_0 | DIRECTION_1 | DIRECTION_2 | DIRECTION_3 |
			DIRECTION_4 | DIRECTION_5 | DIRECTION_6 | DIRECTION_7;
	
	public static int getIndexFromDirection(int direction) {
		return (int) Math.getExponent(direction);
	}
	
	public static int getDirectionFromIndex(int index) {
		return (int) Math.pow(2, index);
	}
	
	public static int getDirection(int direction) {
		return DIRECTION_ALL & direction;
	}
	
	public static boolean hasDirection(int direction, int directions) {
		return (directions & direction) == direction;
	}
	
	public static boolean hasDirection(int direction) {
		return hasDirection(direction, DIRECTION_ALL);
	}
	
}
